package test;

import java.util.List;

import bean.entity.Book;
import bean.entity.User;
import dao.BookDao;
import dao.UserDao;
import dao.test.AccountDaoByBatis;
import dao.test.BookDaoByBatis;
import dao.test.UserDaoByBatis;
import service.BookService;
import service.PurchaseService;
import service.UserService;
import service.impl.BookServiceImpl;
import service.impl.PurchaseServiceImpl;
import service.impl.UserServiceImpl;

public class test {
	public static void main(String[] args) {
		UserServiceImpl us = new UserServiceImpl();
		us.setUd(new UserDaoByBatis()); us.setAd(new AccountDaoByBatis());
		
		
		BookServiceImpl bs = new BookServiceImpl();
		bs.setBd(new BookDaoByBatis());
		
		PurchaseServiceImpl ps = new PurchaseServiceImpl();
		ps.setAd(new AccountDaoByBatis());
		ps.setBs(bs);
		ps.setUs(us);
		
		User user = new User("0","0","1","0");
		us.register(user);
//		System.out.println(us.validate("0","1"));
		
//		System.out.println(us.getUser("0").getBalance());
		var book = new Book("b123", "老人与海", "empty", 20, 5);
		bs.add(book);
		
		
		
		System.out.println(ps.buy(book, user, 6).toString());
		
		System.out.println(us.getUser("0").getBalance());
		
		for (Book b : bs.getBooks()) {
			System.out.println(b.getName()+ "\t" + b.getAmount());
		}
	}
}
